Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: don't compress on x-no-compression header #208

Closed
wants to merge 1 commit into from

Conversation

bjohansebas
Copy link
Member

@bjohansebas bjohansebas commented Dec 5, 2024

We should observe when X-No-Compression is sent in the request.

Copy link
Member

@IamLizu IamLizu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function shouldCompress (req, res) {
  var type = res.getHeader('Content-Type')
  var noCompressionHeader = res.getHeader('x-no-compression')

  if (noCompressionHeader) {
    debug('%s not compressed', type)
    return false
  }

  if (type === undefined || !compressible(type)) {
    debug('%s not compressible', type)
    return false
  }

  return true
}

PS: I don't know why but I am not seeing the commit suggestion feature right now, so I have given the code in comment.

index.js Outdated Show resolved Hide resolved
Copy link
Member

@IamLizu IamLizu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ctcpip
Copy link
Member

ctcpip commented Jan 18, 2025

we shouldn't hardcode tbis behavior. x-no-compression is not a standard http header. the readme already has an example of how to do this within application code

Copy link
Member

@ctcpip ctcpip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above comment

@wesleytodd
Copy link
Member

For those looking for the doc referenced above:

https://github.com/expressjs/compression?tab=readme-ov-file#filter-1


How do we feel about adding an option for this? While I agree we should not hard code this non-standard behavior, it is quite common for libraries and proxies to implement handling for commonly used non-standard headers. This one feels to me like a reasonable one to support in that way.

@ctcpip
Copy link
Member

ctcpip commented Jan 21, 2025

hmm, this is where the 'design goals and non-goals' reference might help, but this does not seem to rise to the level of necessitating a first-class option, particularly as it is very easily accomplished in user code

@wesleytodd
Copy link
Member

Agreed on the design principals, but I think most of the time those docs should include a "pragmatism clause" to ensure that the guide is not used as a hammer. I agree we could make a better decision if we had clarity, but this options specifically feels like a trade-off since we already take many options for how this package handles compression variations. This seems like small addition following the precedent.

@ctcpip
Copy link
Member

ctcpip commented Jan 23, 2025

Most of the options are options for zlib. Without them, the user would have no way of setting those values. Aside from filter, it seems only threshold and enforceEncoding stand out.

100% agree on the pragmatism. While this would be a small addition, it’s important to ensure that changes are driven by a clear and concrete problem. In this case, it seems like a solution in search of a problem, and I would suggest that the problem may not exist.

If we search public code, we see there are less than 100 instances of this header appearing in source code, which indicates very little real world usage.

That said, I may be missing something that you have identified. Could you please help me better understand the specific issue this addition is intended to address?

@wesleytodd
Copy link
Member

Yeah, a clear description of the problem and where it manifests would be awesome. I am hesitant to add the option with results like that, and I know personally I have never seen this header in use in my work.

@bjohansebas
Copy link
Member Author

Yes, I can actually use the filter instead of adding it directly to the package, unless other people also need it, but for now, I don’t think so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants